﻿using System;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;


public partial class ReportesIva : System.Web.UI.Page
{
    #region Propiedades Publicas
    //paso de un parametro
    public ParameterField crtParamField = new ParameterField();
    public ParameterFields crtParamFields = new ParameterFields();
    public ParameterDiscreteValue paramValue = new ParameterDiscreteValue();

    public ParameterField crtParamField2 = new ParameterField();
    public ParameterFields crtParamFields2 = new ParameterFields();
    public ParameterDiscreteValue paramValue2 = new ParameterDiscreteValue();

    public ReportDocument rep = new ReportDocument();
    #endregion

    #region Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
   
        }
        else
        {
            CrystalReportViewer1.ReportSource = Session["ReporteIvaAsignacion"];
            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.ParameterFieldInfo = crtParamFields;
        }

    }

    #endregion

    #region GeneraRecursosIvaXDepartamento
    private void GeneraRecursosIvaXDepartamento(string strVigenca, string strDepartamento )
    {

        ConnectionInfo connInfo = new ConnectionInfo();
        connInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];
        connInfo.DatabaseName = ConfigurationManager.AppSettings["DatabaseName"];
        connInfo.UserID = ConfigurationManager.AppSettings["UserID"];
        connInfo.Password = ConfigurationManager.AppSettings["Password"];
        rep.Load(Server.MapPath("Reportes\\Recursos_IVA_Departamento.rpt"), OpenReportMethod.OpenReportByTempCopy);
        CrystalReportViewer1.ReportSource = rep;
        Tables repTbls = rep.Database.Tables;

        paramValue.Value = strVigenca;
        crtParamField.ParameterFieldName = "@IVI_ID";
        crtParamField.CurrentValues.Add(paramValue);crtParamFields.Add(crtParamField);

        if (strDepartamento != "")
        {
            paramValue2.Value = strDepartamento;
            crtParamField2.ParameterFieldName = "@ZON_ID";
            crtParamField2.CurrentValues.Add(paramValue2);
            crtParamFields.Add(crtParamField2);
        }
        else
        {
         //   paramValue2.Value = strDepartamento;
            crtParamField2.ParameterFieldName = "@ZON_ID";
            crtParamField2.CurrentValues.Add(paramValue2);
            crtParamFields.Add(crtParamField2);
        }
        

        foreach (CrystalDecisions.CrystalReports.Engine.Table repTbl in repTbls)
        {
            TableLogOnInfo repTblLogonInfo = repTbl.LogOnInfo;
            repTblLogonInfo.ConnectionInfo = connInfo;
            repTbl.ApplyLogOnInfo(repTblLogonInfo);
            repTbl.Location = "MCSIG" + ".dbo." + repTbl.Name;
        }

        Session["ReporteIvaAsignacion"] = rep;
        CrystalReportViewer1.ReportSource = rep;
        CrystalReportViewer1.DataBind();

        CrystalReportViewer1.ParameterFieldInfo = crtParamFields;
    }
    #endregion

    #region btnReporteIvaAsignacion_Click

    protected void btnReporteIvaAsignacion_Click(object sender, EventArgs e)
    {
        try
        {
            GeneraRecursosIvaXDepartamento(ddlAnos.SelectedValue, "" );
        }
        catch (Exception ex)
        {
            lblMensaje.Text = ex.Message;
        }
    }

    #endregion

    protected void btnReporteGirosPorDepartamento_Click(object sender, EventArgs e)
    {
        try
        {
            ConnectionInfo connInfo = new ConnectionInfo();
            connInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];
            connInfo.DatabaseName = ConfigurationManager.AppSettings["DatabaseName"];
            connInfo.UserID = ConfigurationManager.AppSettings["UserID"];
            connInfo.Password = ConfigurationManager.AppSettings["Password"];
            rep.Load(Server.MapPath("Reportes\\Giros_Ejecucion_Por_Dpto.rpt"), OpenReportMethod.OpenReportByTempCopy);
            CrystalReportViewer1.ReportSource = rep;
            Tables repTbls = rep.Database.Tables;

            //paramValue.Value = TraerFilasSeleccionadasDelGrid();
            //crtParamField.ParameterFieldName = "@PLN_ID";
            //crtParamField.CurrentValues.Add(paramValue);
            //crtParamFields.Add(crtParamField);

            foreach (Table repTbl in repTbls)
            {
                TableLogOnInfo repTblLogonInfo = repTbl.LogOnInfo;
                repTblLogonInfo.ConnectionInfo = connInfo;
                repTbl.ApplyLogOnInfo(repTblLogonInfo);
                repTbl.Location = "MCSIG" + ".dbo." + repTbl.Name;
            }
            Session["ReporteIvaAsignacion"] = rep;
            CrystalReportViewer1.ReportSource = rep;
            CrystalReportViewer1.DataBind();
            //CrystalReportViewer1.ParameterFieldInfo = crtParamFields;
        }
        catch (Exception ex)
        {
            lblMensaje.Text = ex.Message;
        }
    }
    protected void btnReporteEjecucionProyectosIva_Click(object sender, EventArgs e)
    {
        try
        {
            ConnectionInfo connInfo = new ConnectionInfo();
            connInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];
            connInfo.DatabaseName = ConfigurationManager.AppSettings["DatabaseName"];
            connInfo.UserID = ConfigurationManager.AppSettings["UserID"];
            connInfo.Password = ConfigurationManager.AppSettings["Password"];
            rep.Load(Server.MapPath("Reportes\\Ejecucion_Proyectos_IVA.rpt"), OpenReportMethod.OpenReportByTempCopy);
            CrystalReportViewer1.ReportSource = rep;
            Tables repTbls = rep.Database.Tables;

            //paramValue.Value = TraerFilasSeleccionadasDelGrid();
            //crtParamField.ParameterFieldName = "@PLN_ID";
            //crtParamField.CurrentValues.Add(paramValue);
            //crtParamFields.Add(crtParamField);

            foreach (Table repTbl in repTbls)
            {
                TableLogOnInfo repTblLogonInfo = repTbl.LogOnInfo;
                repTblLogonInfo.ConnectionInfo = connInfo;
                repTbl.ApplyLogOnInfo(repTblLogonInfo);
                repTbl.Location = "MCSIG" + ".dbo." + repTbl.Name;
            }
            Session["ReporteIvaAsignacion"] = rep;
            CrystalReportViewer1.ReportSource = rep;
            CrystalReportViewer1.DataBind();
            //CrystalReportViewer1.ParameterFieldInfo = crtParamFields;
        }
        catch (Exception ex)
        {
            lblMensaje.Text = ex.Message;
        }

    }
    protected void btnReporteDetallePlanInversion_Click(object sender, EventArgs e)
    {
        try
        {
            ConnectionInfo connInfo = new ConnectionInfo();
            connInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];
            connInfo.DatabaseName = ConfigurationManager.AppSettings["DatabaseName"];
            connInfo.UserID = ConfigurationManager.AppSettings["UserID"];
            connInfo.Password = ConfigurationManager.AppSettings["Password"];
            rep.Load(Server.MapPath("Reportes\\Detalle_Plan_Inversion.rpt"), OpenReportMethod.OpenReportByTempCopy);
            CrystalReportViewer1.ReportSource = rep;
            Tables repTbls = rep.Database.Tables;

            //paramValue.Value = TraerFilasSeleccionadasDelGrid();
            //crtParamField.ParameterFieldName = "@PLN_ID";
            //crtParamField.CurrentValues.Add(paramValue);
            //crtParamFields.Add(crtParamField);

            foreach (Table repTbl in repTbls)
            {
                TableLogOnInfo repTblLogonInfo = repTbl.LogOnInfo;
                repTblLogonInfo.ConnectionInfo = connInfo;
                repTbl.ApplyLogOnInfo(repTblLogonInfo);
                repTbl.Location = "MCSIG" + ".dbo." + repTbl.Name;
            }
            Session["ReporteIvaAsignacion"] = rep;
            CrystalReportViewer1.ReportSource = rep;
            CrystalReportViewer1.DataBind();
            //CrystalReportViewer1.ParameterFieldInfo = crtParamFields;
        }
        catch (Exception ex)
        {
            lblMensaje.Text = ex.Message;
        }
    }
}
